import React from 'react'
import { Table } from 'antd'
import moment from 'moment'
import { download } from '@js/downloadRename'
// 获取主表格配置
export function getMainColumns () {
  return [
    { title: '序号', dataIndex: 'index', key: 'index', align: 'center', width: '80px' },
    { title: '提交人', dataIndex: 'submittal', key: 'submittal' },
    { title: '提交人类型', dataIndex: 'submittal_type', key: 'submittal_type' },
    { title: '证据名称', dataIndex: 'name', key: 'name' },
    { title: '证据内容', dataIndex: 'proof', key: 'proof' },
    {
      title: '创建时间',
      dataIndex: 'create_datetime',
      key: 'create_datetime',
      render: (v) => {
        if (v) {
          return moment(v * 1000).format('YYYY-MM-HH')
        }
      }
    }
  ]
}

// 处理证据数据
export function dealData (list) {
  return list.map((li, i) => {
    li.index = i + 1
    return li
  })
}

export const expandedRowRender = (setSignature, setVisible) => {
  return (record, index) => {
    const columns = [
      { title: '序号', dataIndex: 'index', key: 'index', width: 80 },
      {
        title: '名称',
        dataIndex: 'original_filename',
        key: 'original_filename',
        render: (v, l) => {
          const n = v || l.filename
          if (n) {
            return <a onClick={() => download(l.path, n)}>{n}</a>
          }
        }
      },
      {
        title: '电子数据核验情况',
        dataIndex: 'signature',
        key: 'signature',
        render: (v) => {
          if (v !== null) {
            return <a onClick={() => { setSignature(dealData(v)); setVisible(true) }}>查看详情</a>
          }
        }
      }
    ]
    const l = (record.file || []).map((li, i) => {
      li.index = i + 1
      return li
    })
    return <Table rowKey='index' columns={columns} dataSource={l} pagination={false} />
  }
}
